import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yp/helper.dart';

import '../logic.dart';
import '../state.dart';

class TurntableTabBar extends StatelessWidget {
  final logic = Get.find<TurntableAwardLogic>();
  final TurntableAwardState state = Get.find<TurntableAwardLogic>().state;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<TurntableAwardLogic>(
        builder: (logic) => Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: state.titles
                .asMap()
                .map((key, value) => MapEntry(
                    key,
                    _getItem(value,
                        isChoosed: state.currentIndex == key,
                        onTap: () => logic.tabClick(key))))
                .values
                .toList()));
  }

  Widget _getItem(String title, {bool isChoosed = false, VoidCallback onTap}) {
    return InkWell(
      onTap: onTap,
      child: Container(
        width: setWidth(350),
        height: setWidth(80),
        alignment: Alignment.center,
        decoration: BoxDecoration(
            gradient: LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: isChoosed
                    ? [Color(0xffFFE4E6), Colors.white]
                    : [Colors.white, Color(0xffFFE4E6)]),
            borderRadius: BorderRadiusDirectional.vertical(
                top: Radius.circular(setWidth(20)))),
        child: Text(
          title,
          style: TextStyle(
              color: Color(isChoosed ? 0xff79050C : 0xffCD868A),
              fontSize: setWidth(28)),
        ),
      ),
    );
  }
}
